# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=osl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.2
pkgrel=1
pkgdesc="OpenScop Library (mingw-w64)"
arch=('any')
url="https://icps.u-strasbg.fr/people/bastoul/public_html/development/openscop/index.html"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gmp")
source=("https://github.com/periscop/openscop/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-osl-0.9.2-fix-shared-libs.patch")
sha256sums=('eee5cd9bf5b3b8491f95f681cfaa987344f0fb3d7499f5d8e19e3ce75e0c5ed0'
            '6bf93072709b1b81feaddcb15078e8d48a6b08c573810328516dd21915f8eb18')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-osl-0.9.2-fix-shared-libs.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --with-gmp=system \
    --with-gmp-prefix=${MINGW_PREFIX}
  
  # Just build library and header includes target since tests will fail from lack of posix headers
  make libosl.la include/osl/scop.h
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make install-libLTLIBRARIES install-pkgincludeHEADERS DESTDIR="${pkgdir}"
  install -D -m644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
